﻿#ifndef LOGINDLG_H
#define LOGINDLG_H

#include "FrameGlobal.h"
#include "BaseInclude.h"
#include "FrameStruct.h"
#include <QDialog>

enum TREE_ROLE_USER
{
	TREE_ROLE_USERCODE = TREE_ROLE_PID + 1,
	TREE_ROLE_USERNAME,
	TREE_ROLE_DEPTNAME,
	TREE_ROLE_DEPTID,
	TREE_ROLE_PASSWD
};

class UserInfoDlg;
class FrameHelper;
class OrganizationTree;
namespace Ui {class LoginDlg;};

//typedef bool(*FUNC)(const QString & name, const QString & pwd, QString & error);
class FRAME_EXPORT LoginDlg : public QDialog
{
	Q_OBJECT

public:
	LoginDlg(QWidget *parent = 0);
	~LoginDlg();

public:
	/*字段 ID， PID， NAME, CODE, PASSWD*/
	bool login(const QString & SQL, const QVariant & Root);
	static UserInfo getUserInfo();

protected:
	bool initModel(QString & Error);
	bool check(const QString & name, const QString & pwd, QString & error);
	bool eventFilter(QObject * obj, QEvent * e);
	virtual void keyPressEvent(QKeyEvent *e);

protected slots:
	void on_btnLogin_clicked();

private:
	Ui::LoginDlg *ui;

//	FUNC func;
	bool bLogin;
	QString strSQL;
	QVariant varRoot;
	UserInfoDlg *pDlgUser;
	OrganizationTree * pOrgTree;
	FrameHelper * pFrameHelper;

	static UserInfo userInfo;
};

/***********************************************************************************************************************************/
//Model
class OrganizationTree : public QRecordTreeModel
{
public:
	OrganizationTree(QObject * parent = 0);
	~OrganizationTree();

protected:
	virtual QVariant data(const QModelIndex &index, int role) const;
	virtual Qt::ItemFlags flags(const QModelIndex &index) const;

private:

};

/***********************************************************************************************************************************/
#endif // LOGINDLG_H
